#!/usr/bin/env python3
# coding: utf-8

from __future__ import print_function
import sys, heapq


class Node:
    """vertex"""

    def __init__(self, edges=[]):
        self.edges = edges
        self.visited = False
        self.distance = 1<<64

    def __repr__(self):
        return '<Node  {0} edges,{1} distance={2}>'.format(len(self.edges),
                                                           ' visited,' if self.visited else '',
                                                           self.distance)

#@profile
def prim(V, E):
    """prim's alg."""
    # TODO: explain data types etc.
    E_q = []
    mst = []
    mst_weight = 0

    # new edge type
    #E_q = sorted([E[x] for x in V[0].edges[2]])
    i = 0
    while i < len(V[0].edges):
        E_q.append(E[V[0].edges[i][2]])
        assert E[V[0].edges[i][2]][2] == False, 'you make no sense'
        E[V[0].edges[i][2]][2] = True
        i += 1
    heapq.heapify(E_q)
    V[0].visited = True
    V[0].distance = 0

    while True:
        if len(E_q) == 0:
            break

        edge = heapq.heappop(E_q)
        assert edge[2] == True, 'a not-enqueued item was extracted from the queue'

        if (V[edge[1][0]].visited, V[edge[1][1]].visited) == (True, True):
            continue

        (cur_vtx, next_vtx) = tuple(sorted(edge[1], key=lambda x: V[x].visited, reverse=True))
        assert V[cur_vtx].visited == True, 'queue order error'
        assert V[next_vtx].visited == False, 'what\'s the point then?'
        V[next_vtx].visited = True
        mst.append(edge)

        for adj_edge in V[next_vtx].edges:
            if not E[adj_edge[2]][2] and not V[adj_edge[0]].visited:
                E[adj_edge[2]][2] = True  # XXX
                heapq.heappush(E_q, E[adj_edge[2]])
        print('len(E_q) = {}'.format(len(E_q)), file=sys.stderr)

    for vtx in V:
        if not vtx.visited:
            print('no minimum spanning tree', file=sys.stderr)
            return None

    for edge in mst:
        mst_weight += edge[0]

    return mst_weight

if __name__ == "__main__":
    infile = open(sys.argv[1])

    vertexes = [Node([]) for i in range(int(infile.readline().rstrip()))]
    edges = []
    edge_idx = 0

    for line in infile.readlines():
        line = line.strip()
        line = [int(n) for n in line.split()]
        line[0] -= 1
        line[1] -= 1
        vertexes[line[0]].edges.append((line[1], line[2], edge_idx))
        vertexes[line[1]].edges.append((line[0], line[2], edge_idx))
        edges.append([line[2], tuple(sorted((line[0], line[1]))), False])
        edge_idx += 1
    print(prim(vertexes, edges))
